package com.cskaoyan.controller.mall;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.CommonData;
import com.cskaoyan.bean.po.ohter.MarketBrand;
import com.cskaoyan.service.mall.BrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;

/**
 * @Author Ajun de BBC
 * @Date 2022/7/20 10:49
 * @Version 1.5
 */

@RestController
@RequestMapping("admin/brand")
public class BrandController {

    @Autowired
    BrandService brandService;

    @RequestMapping("list")
    public BaseRespVo brandList(Integer page,Integer limit,Integer id,String name,String sort,String order){
        CommonData<MarketBrand> marketBrandVo = brandService.brandList(page,limit,id,name,sort,order);
        return BaseRespVo.ok(marketBrandVo,"成功",0);
    }

    @RequestMapping("create")
    public BaseRespVo brandCreate(@RequestBody MarketBrand marketBrand){
        if((marketBrand.getDesc() == null || marketBrand.getDesc().length() <= 0) ||
                (marketBrand.getFloorPrice() == null || marketBrand.getFloorPrice().compareTo(new BigDecimal(0)) <= 0)){
            return BaseRespVo.ok(null,"参数不对",401);
        }
        MarketBrand marketBrandInfo = brandService.brandCreate(marketBrand);
        if (marketBrandInfo == null){
            return BaseRespVo.ok(null,"制造商名称不能相同",401);
        }
        return BaseRespVo.ok(marketBrandInfo,"成功",0);
    }

    @RequestMapping("update")
    public BaseRespVo brandUpdate(@RequestBody MarketBrand marketBrand){
        if((marketBrand.getDesc() == null || marketBrand.getDesc().length() <= 0) ||
                (marketBrand.getFloorPrice() == null || marketBrand.getFloorPrice().compareTo(new BigDecimal(0)) <= 0)){
            return BaseRespVo.ok(null,"参数不对",401);
        }
        MarketBrand marketBrandInfo = brandService.brandUpdate(marketBrand);
        if (marketBrandInfo == null){
            return BaseRespVo.ok(null,"制造商名称不能相同",401);
        }
        return BaseRespVo.ok(marketBrandInfo,"成功",0);
    }


    @RequestMapping("delete")
    public BaseRespVo brandDelete(@RequestBody MarketBrand marketBrand){
        brandService.brandDelete(marketBrand);
        return BaseRespVo.ok(null,"成功",0);
    }
















}
